package uml.objects;

import java.awt.Component;
import java.awt.Container;
import java.awt.Point;

/**
 * @author Evan Curtis
 *
 */
public class AnchorPoint extends Point implements Translatable {	
	private Container m_context;
	/**
	 * Creates a new object at <tt>Point</tt> location in the coordinate system of <tt>Container</tt> context
	 * @param location
	 * @param c
	 */
	public AnchorPoint(Point location, Container context) 
	{
		x = location.x;
		y = location.y;
		m_context = context;
	}
	/**
	 * Creates a new object at point <x,y> in the coordinate system of <tt>Container</tt> context
	 * @param x
	 * @param y
	 * @param c
	 */
	public AnchorPoint(int x, int y, Container context) 
	{
		this.x = x;
		this.y = y;
		m_context = context;
	}
	/**Returns true if p is within 5 pixels of this <tt>AnchorPoint</tt>
	 * @param p
	 */
	@Override
	public boolean select(Point p) {
		return (this.distance(p) < 5); 
	}
	/**
	 * Converts the Coordinates to its top level container's coordinates
	 * @return
	 */
	public Point convertCoordsToContainer()
	{
		//Point transform = m_context.getLocationOnScreen();
		Component currentContext;
		Point transform = new Point(this);
		for(currentContext = m_context; currentContext.getParent() != null; currentContext = currentContext.getParent())
		{
			transform.x += currentContext.getX();
			transform.y += currentContext.getY();
		}
		return transform;
	}
}